home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8631 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: cs.ruu.nl!usenet
  2. From: piet@stego.cs.ruu.nl (Piet van Oostrum)
  3. Newsgroups: comp.lang.pascal.misc,comp.lang.c++,comp.lang.c,comp.lang.pascal.borland
  4. Subject: Re: Tough FACTORIAL math problem...
  5. Date: 16 Feb 1996 12:27:42 +0100
  6. Organization: Universiteit Utrecht, Dept. of Computer Science
  7. Sender: piet@stego.cs.ruu.nl
  8. Message-ID: <wzvil7wlw1.fsf@stego.cs.ruu.nl>
  9. References: <4fr8be$ass@news.iconn.net> <wzenrwg142.fsf@stego.cs.ruu.nl>
  10.     <4fvorm$dfm@beach.and.nl>
  11. NNTP-Posting-Host: stego.cs.ruu.nl
  12. In-reply-to: jos@and.nl's message of 15 Feb 1996 17:00:38 GMT
  13. X-Newsreader: Gnus v5.0.8
  14.  
  15. >>>>> jos@and.nl (Jos A. Horsmeier) (JAH) writes:
  16.  
  17. JAH> In article <wzenrwg142.fsf@stego.cs.ruu.nl>, piet@stego.cs.ruu.nl wrote:
  18. JAH> |>>>>> thecrow@iconn.net (The Crow) (TC) writes:
  19. JAH> |
  20. JAH> |TC> Here is what I am trying to do, I want to find the last NON-ZERO digit
  21. JAH> |TC> of a given factorial. For instance,
  22. JAH> |
  23. JAH> |TC> 5! = 120
  24. JAH> |
  25. JAH> |TC> so the last non-zero digit is 2. I want to be able to do this up to
  26. JAH> |TC> 1000. Problem is, no matter how huge of a data-type you use, there
  27. JAH> |TC> isn't any way for the computer to handle 1000!, it is however possible
  28.  
  29. JAH> |A little thinking before coding solves this problem very easily:
  30. JAH> |
  31. JAH> |Let N be then number whose factorial you are considering.
  32. JAH> |
  33. JAH> |What you want is the number of trailing zeroes + 1. 
  34.  
  35. JAH> [ clever solution of not-the-posters-problem deleted ... ]
  36.  
  37. JAH> No, that's not what he wanted. A little reading before thinking before
  38. JAH> coding may come in handy sometimes ;-) What the original poster wants
  39. JAH> is the value of the rightmost non-zero digit of n!. 
  40.  
  41. Sorry, I guess that I wrongly interpreted the meaning of the word "find" in
  42. the original question. 
  43. -- 
  44. Piet van Oostrum <piet@cs.ruu.nl>
  45. http://www.cs.ruu.nl/~piet
  46.